
//2260.必须拿起的最小连续卡牌数
class Solution {
public:
    int minimumCardPickup(vector<int>& cards) {
        int n=cards.size();
        unordered_map<int,int> m; //存储左边的卡牌值和位置

        int ret=INT_MAX;
        for(int i=0;i<n;i++)
        {
            if(m.count(cards[i])) ret=min(ret,i-m[cards[i]]+1);  

            m[cards[i]]=i;
        }
        return ret==INT_MAX?-1:ret;
    }
};